const app = getApp()
//获得全局js变量
var util = require('../../utils/util.js');
Page({
    /**
     * 页面的初始数据
     */
    data: {
        banner:[],
        goodCate:[],
        goodList:[],
        news:[],
        userFid:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.setStorageSync('prevurl','index');
		if(options.userFid){
            wx.setStorageSync('userFid',options.userFid);
            app.globalData.userFid = options.userFid; 
        }else if(options.scene){
            wx.setStorageSync('userFid',options.scene);
            app.globalData.userFid = options.userFid;
        }
        this.getBanner();
        this.getGoodCate();
        this.getGoodList();
        this.getNews();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    noticeList:function(){
        wx.navigateTo({
            url: '/pages/noticelist/noticelist'
        })
    },
    jumpfenlei:function(e){
        let i = e.currentTarget.dataset.id;
        wx.setStorageSync('fenleiid', i);
        wx.switchTab({
            url: '/pages/cate/cate',
          })
        
    },
    getBanner:function(){
        var that=this;
        util.httpRrquest(app.data.rooturl + 'system/getBanner', 'GET')
        .then(function (response) {
            that.setData({
                banner: response.data.data
            })
        }, function (error) {
            console.log(error);
        });
    },
    getGoodCate:function(){
        var that=this;
        util.httpRrquest(app.data.rooturl + 'mall/getGoodCate', 'GET', {length:10})
        .then(function (response) {
            that.setData({
                goodCate: response.data.data
            })
        }, function (error) {
            console.log(error);
        });
    },
    getGoodList:function(){
        var that=this;
        util.httpRrquest(app.data.rooturl + 'mall/getGoodList?index=1', 'GET')
        .then(function (response) {
            that.setData({
                goodList: response.data.data
            })
        }, function (error) {
            console.log(error);
        });
    },
    getNews:function(){
        var that=this;
        util.httpRrquest(app.data.rooturl + 'system/getNews', 'GET')
        .then(function (response) {
            that.setData({
                news: response.data.data
            })
        }, function (error) {
            console.log(error);
        });
	},
	newDetail:function(e){
        let i = e.currentTarget.dataset.id;
		wx.navigateTo({
			url: '/pages/newDetail/newDetail?id='+i
		})
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },
    
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function (res) {
        var shareinfo = app.setShareMessage();
        console.log(shareinfo);
        return {
            title: shareinfo.title,
            path: shareinfo.path,
            imageUrl: shareinfo.imageUrl,
            success: (res) => {
                wx.showToast({
                    title: "分享成功",
                    icon: 'loading'
                })
            }
        }
        
    }
})